//
//  SMSalertsViewController.m
//  HondaPro_2
//
//  Created by ht on 13-6-24.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "SMSalertsViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "webConfig.h"
#import "webService.h"
@interface SMSalertsViewController ()
{
    BOOL _noticeHoose;
    BOOL _voiceHoose;
}

@end

@implementation SMSalertsViewController

@synthesize noticeLabel = _noticeLabel;

@synthesize noticeButton = _noticeButton;
@synthesize voiceButton = _voiceButton;
@synthesize phonefield = _phonefield;
@synthesize noteTextView = _noteTextView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setFrame:CGRectMake(0, 0, 500, 530)];
    
    [self loadfixedlabel];
    [self loadViewCall];
    
    //短信
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getDefaultMobile:) name:MM_GET_DEFAULT_MOBILE_ object:nil];
    //提醒
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendSMS:) name:SENDSMS object:nil];

}
-(void)getDefaultMobile:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
    self.phonefield.text = [theJson objectForKey:@"defaultMobile"];
}
-(void)loadfixedlabel
{
    UILabel *imagetitel = [[UILabel alloc]initWithFrame:CGRectMake(25, 20, 100, 35)];
    imagetitel.text = @"客户提醒";
    imagetitel.backgroundColor = [UIColor clearColor];
    imagetitel.textColor = [UIColor grayColor];
    imagetitel.font = [UIFont fontWithName:@"ArialMT" size:17];
    [self.view addSubview:imagetitel];
    
    UIImageView *imageline= [[UIImageView alloc]initWithFrame:CGRectMake(15, 55, 470, 2)];
    imageline.image = [UIImage imageNamed:@"红色分割线.png"];
    [self.view addSubview:imageline];
    
    UILabel *notice = [[UILabel alloc]initWithFrame:CGRectMake(100, 80, 90, 30)];
    notice.text = @"短信通知";
    notice.backgroundColor = [UIColor clearColor];
    notice.textColor = [UIColor grayColor];
    notice.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.view addSubview:notice];
    
    UILabel *phone = [[UILabel alloc]initWithFrame:CGRectMake(70, 130, 90, 30)];
    phone.text = @"手机号码:";
    phone.backgroundColor = [UIColor clearColor];
    phone.textColor = [UIColor grayColor];
    phone.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.view addSubview:phone];
    
    UILabel *voice = [[UILabel alloc]initWithFrame:CGRectMake(100, 360, 90, 30)];
    voice.text = @"语音提醒";
    voice.backgroundColor = [UIColor clearColor];
    voice.textColor = [UIColor grayColor];
    voice.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.view addSubview:voice];
    
    UIButton *determine = [[UIButton alloc]initWithFrame:CGRectMake(260, 420, 73, 33)];
    [determine setTitle:@"确定" forState:UIControlStateNormal];
    [determine setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [determine setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    determine.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [determine addTarget:self action:@selector(determine:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:determine];
    
    UIButton *cancel = [[UIButton alloc]initWithFrame:CGRectMake(360, 420, 75, 35)];
    [cancel setTitle:@"取消" forState:UIControlStateNormal];
    [cancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancel setBackgroundImage:[UIImage imageNamed:@"改-灰but.png"] forState:UIControlStateNormal];
    cancel.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [cancel addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancel];
    
    self.noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(240, 80, 220, 30)];
    self.noticeLabel.text = @"作业单制作时，未要求短信通知";
    self.noticeLabel.backgroundColor = [UIColor clearColor];
    self.noticeLabel.textColor = [UIColor redColor];
    self.noticeLabel.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.view addSubview:self.noticeLabel];
}
-(void)loadViewCall
{
    self.noticeButton = [UIButton buttonWithType:UIButtonTypeCustom];    //是否短信通知
    [self.noticeButton setFrame:CGRectMake(65, 78, 30, 30)];
    [self.noticeButton setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
    [self.noticeButton addTarget:self action:@selector(noticeButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.noticeButton];
    
    self.voiceButton = [UIButton buttonWithType:UIButtonTypeCustom];    //是否语音提醒
    [self.voiceButton setFrame:CGRectMake(65, 358, 30, 30)];
    [self.voiceButton setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
    [self.voiceButton addTarget:self action:@selector(voiceButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.voiceButton];
    
    self.phonefield = [[UITextField alloc]initWithFrame:CGRectMake(150, 133, 180, 24)];    //手机号
    self.phonefield.borderStyle = UITextBorderStyleLine;
    self.phonefield.textColor = [UIColor grayColor];
    self.phonefield.font = [UIFont fontWithName:@"ArialMT" size:14];
    [self.view addSubview:self.phonefield];
    
    self.noteTextView = [[UITextView alloc]initWithFrame:CGRectMake(70, 190, 370, 150)];
    [self.noteTextView setFont:[UIFont fontWithName:@"ArialMT" size:14]];
    self.noteTextView.textColor = [UIColor grayColor];
    self.noteTextView.layer.borderColor = [[UIColor grayColor]CGColor];
    self.noteTextView.text = self.chePaiNember;
    self.noteTextView.layer.borderWidth = 0.9;
    [self.view addSubview:self.noteTextView];
}
#pragma mark - 确定按钮的回调方法
-(void)determine:(id)sender
{
    NSString *noticeType = @"";
    if(_noticeHoose == YES && _voiceHoose == NO)
    {
        noticeType = @"0";
    }
    else if(_voiceHoose == YES && _noticeHoose == NO)
    {
        noticeType = @"1";
    }
    else if(_noticeHoose == YES && _voiceHoose == YES )
    {
        noticeType = @"2";
    }
    else
    {
//        NSLog(@"请选择提醒类型！");
    }
    
    if(self.phonefield.text != nil)
    {
        NSMutableDictionary *sendSMSdic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:noticeType,@"noticeType",self.phonefield.text,@"mobile",self.chePaiNember,@"noticeContent",nil];

        webService *web=[[webService alloc] init];
        web.methodName = SENDSMS;
        [web commonPostSharedRequest:SENDSMS psotDic:sendSMSdic];
    }
}
-(void)sendSMS:(NSNotification *)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
//    NSLog(@"%@",[theJson objectForKey:@"error_code"]);
}
#pragma mark - 取消按钮的回调方法
-(void)cancel:(id)sender
{
    
}

-(void)noticeButton:(id)sender
{
    if(_noticeHoose == YES)
    {
        _noticeHoose = NO;
        [self.noticeButton setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
        [self.noticeLabel setHidden:NO];
    }
    else
    {
        _noticeHoose = YES;
        [self.noticeButton setImage:[UIImage imageNamed:@"对号.png"] forState:UIControlStateNormal];
        [self.noticeLabel setHidden:YES];
    }
}

-(void)voiceButton:(id)sender
{
    if(_voiceHoose == YES)
    {
        _voiceHoose = NO;
        [self.voiceButton setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
    }
    else
    {
        _voiceHoose = YES;
        [self.voiceButton setImage:[UIImage imageNamed:@"对号.png"] forState:UIControlStateNormal];
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end